Column

Overall Sightings Map and Heat Map

# A tibble: 115,424 × 2
# Groups:   location [115,424]
   location                                     n
   <chr>                                    <int>
 1 (40.499501974690006, -74.23978983692255)     1
 2 (40.49953214505736, -74.23980073207275)      2
 3 (40.49967332981336, -74.2379063249761)       3
 4 (40.49972063717932, -74.2389168747568)       1
 5 (40.49980556501166, -74.23767307701547)      1
 6 (40.4998111485254, -74.23894955916211)       2
 7 (40.49984206806492, -74.23991690494499)      1
 8 (40.50000122044222, -74.23729982186418)      2
 9 (40.5003669162799, -74.24483770399796)       1
10 (40.50043247509582, -74.24109841355575)     11
# ℹ 115,414 more rows

Row

---
title: "Interactive Data"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
    theme: simplex
runtime: shiny

---

```{r split = FALSE, fig.align = 'default', warning = FALSE, out.width="100%", include = FALSE, message= FALSE}
library(tidyverse)
library(lubridate)
library(readr) 
library("ggplot2") 
library("dplyr")
library(xts)
library("lubridate")
library("RColorBrewer")
library("ggthemes")
library("gridExtra")
library("leaflet")
library("highcharter")
library(scales)
library(leaflet.extras)

rats_raw <- read.csv("./Rat_Sightings.csv", na = c("", "NA", "N/A", "Unspecified")) %>%
  janitor::clean_names() %>% 
  mutate(created_date = mdy_hms(created_date)) %>%
  mutate(sighting_year = year(created_date),
         sighting_month_num = month(created_date),
         sighting_month = month(created_date, label = TRUE, abbr = FALSE),
         sighting_day = day(created_date),
         sighting_weekday = wday(created_date, label = TRUE, abbr = FALSE)) 
```

Column {.sidebar}
-----------------------------------------------------------------------

Welcome to our interactive dashboard. 


Column {data-width=650}
-----------------------------------------------------------------------

### Overall Sightings Map and Heat Map

```{r}
top = 40.917577 # north lat
left = -74.259090 # west long
right = -73.700272 # east long
bottom =  40.477399 # south lat


nyc = rats_raw %>%
  filter(latitude >= bottom) %>%
  filter ( latitude <= top) %>%
  filter( longitude >= left ) %>%
  filter(longitude <= right)

center_lon = median(nyc$longitude,na.rm = TRUE)
center_lat = median(nyc$latitude,na.rm = TRUE)

count = nyc %>%
  group_by(location) %>%
  count()

count 

nyc = merge(nyc, count, by = "location")

factpal = colorFactor("blue", nyc$n)
```

```{r,fig.align = 'default', warning = FALSE, out.width="100%", echo = FALSE}

nyc %>%
leaflet() %>% 
  addProviderTiles("Esri.NatGeoWorldMap") %>%
  addCircles(lng = ~longitude, lat = ~latitude)  %>%
  setView(lng=center_lon, lat=center_lat,zoom = 10) 

nyc %>%
  leaflet() %>%
  addProviderTiles("Esri.NatGeoWorldMap") %>%
  addHeatmap(lng = ~longitude, lat = ~latitude, intensity = ~(nyc$n), blur = 20, max = 0.05, radius = 15) %>%
  setView(lng=center_lon, lat=center_lat,zoom = 10)

```

Row
-----------------------------------------------------------------------